package com.example.todolist.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.todolist.model.TeamPerDO;
import com.example.todolist.model.TeamPlanDO;
import com.example.todolist.mapper.TeamPlanMapper;
import com.example.todolist.response.BaseResponse;
import com.example.todolist.response.SystemResponse;
import com.example.todolist.service.TeamPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cqq
 * @since 2022-03-21
 */
@Service
public class TeamPlanServiceImpl extends ServiceImpl<TeamPlanMapper, TeamPlanDO> implements TeamPlanService {


    @Override
    public BaseResponse addTeamPlan(List<TeamPlanDO> teamPlanDOS, String code) {
        int i = 0;
        for (TeamPlanDO teamPlanDO : teamPlanDOS) {
            teamPlanDO.setTeamId(code);
           i += this.baseMapper.insert(teamPlanDO);
        }
        if (i == teamPlanDOS.size()) {
            return SystemResponse.success();
        } else {
            return SystemResponse.fail();
        }
    }

    @Override
    public List<TeamPlanDO> selectAll() {
        return this.baseMapper.selectList(null);
    }

    @Override
    public List<TeamPlanDO> selectDetails(String teamID) {
        QueryWrapper<TeamPlanDO> teamPlanDOQueryWrapper = new QueryWrapper<>();
        teamPlanDOQueryWrapper.eq("team_id", teamID);
        return this.baseMapper.selectList(teamPlanDOQueryWrapper);
    }
}
